package config

import (
	"fmt"
	"io/ioutil"

	"gopkg.in/yaml.v2"
)

// ClusterConfig 定义配置文件结构
type ClusterConfig struct {
	Cluster struct {
		Image    []string          `yaml:"image"`
		Masters  []string          `yaml:"masters"`
		Nodes    []string          `yaml:"nodes"`
		Password string            `yaml:"password"`
		Data     []string          `yaml:"data"`
		Env      map[string]string `yaml:"env"` // 添加环境变量配置
	} `yaml:"cluster"`
}

// LoadConfig 读取配置文件
func LoadConfig(filePath string) (*ClusterConfig, error) {
	data, err := ioutil.ReadFile(filePath)
	if err != nil {
		return nil, fmt.Errorf("读取配置文件失败: %v", err)
	}

	config := &ClusterConfig{}
	if err := yaml.Unmarshal(data, config); err != nil {
		return nil, fmt.Errorf("解析配置文件失败: %v", err)
	}
	return config, nil
}
